<?php
require_once("../qq/API/qqConnectAPI.php");
include("../../function/function.php");

$_SESSION['kboy_weibo_login'] = "";

$qc = new QC();

$user_qq_qc = $qc->qq_callback();

$user_qq_openid = $qc->get_openid();

$qc = new QC($user_qq_qc,$user_qq_openid);

$arr = $qc->get_user_info();


if($user_qq_openid){
	if($arr['gender'] == '男'){
		$sex = 1;
	}
	if($arr['gender'] == '女'){
		$sex = 0;
	}
	if(getNewsNums("kboy_user","user_qq_openid='$user_qq_openid'") >0){
		$_SESSION['kboy_qq_login'] = $user_qq_openid;
		$_SESSION['EmailName'] = "";
		$_SESSION['EmailCode'] = "";
		$_SESSION['kboy_phone'] = getClassName("kboy_user","user_phone","user_qq_openid='$user_qq_openid'");
		$_SESSION['kboy_user'] = getClassName("kboy_user","user_nickname","user_qq_openid='$user_qq_openid'");
		$_SESSION['kboy_userid'] = getClassName("kboy_user","uid","user_qq_openid='$user_qq_openid'");
		mysql_query("update kboy_user set user_lasttime='$THIS_TODAY_DATETIME',user_lastip='".getip()."' where user_qq_openid='$user_qq_openid'");
		echo re("../../user_index.php");
	}else{
		$mysql = new sqlstr("kboy_user"); 
		$mysql -> set("user_qq_openid",$user_qq_openid);
		$mysql -> set("user_nickname",$arr["nickname"]);
		$mysql -> set("user_homeprov",$arr["province"]);
		$mysql -> set("user_sex",$sex);
		$mysql -> set("user_homecity",$arr["city"]);
		$mysql -> set("user_face",$arr['figureurl_2']);
		$mysql -> set("user_localprov",$arr["province"]);
		$mysql -> set("user_localcity",$arr["city"]);
		$news_sql = $mysql -> insertSql();
		$news_res = mysql_query($news_sql);
		$uid = mysql_insert_id();
		if($news_res){
			
			$_SESSION['kboy_qq_login'] = $user_qq_openid;
			$_SESSION['kboy_user'] = $arr["nickname"];
			$_SESSION['kboy_userid'] = $uid;
			$_SESSION['kboy_phone'] = '';
			echo re("../../user_index.php");
		}else{
			echo erro("登陆失败");
		}
	}
}else{
	echo erro("参数错误");
}
